package com.hqyj.mana.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hqyj.mana.enums.ResultEnum;
import com.hqyj.mana.pojo.BasicInformation;
import com.hqyj.mana.pojo.vo.ResultVO;
import com.hqyj.mana.service.BasicInfoService;

@Controller
@RequestMapping("userInfo")
public class BasicInfoController {

	//ע��service���BasicInofoService�ӿ�ʵ����
	@Autowired
	BasicInfoService service;

	
	@RequestMapping("get.do")
	@ResponseBody
		
		public ResultVO getBasicInfoList(String userId){
		List<BasicInformation> list = service.selectAllBasicInfo(userId);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(list);
		if(list==null){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
	}
	
	@RequestMapping("insert.do")
	@ResponseBody
	public ResultVO add(@RequestBody BasicInformation user){
		boolean add = service.add(user);
		ResultVO resultVO = new ResultVO();
		if(add!=true){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
	}
	/**
	 * �޸�
	 * @param user
	 * @return
	 */
	@RequestMapping("update.do")
	@ResponseBody
	public ResultVO update(@RequestBody BasicInformation user){
		System.out.println(user.getId());
		boolean update = service.update(user);
		ResultVO resultVO = new ResultVO();
		if(update!=true){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
		
	}

	/**
	 * ɾ��
	 * @param user
	 * @return
	 */
	@RequestMapping("delete.do")
	@ResponseBody
	public ResultVO delete(Integer id){
		boolean delete = service.del(id);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(delete);
		if(delete!=true){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			}
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
	}
	
}
